﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace AwesomeEnginePC.Inputs
{
    public class KeyboardInputs : BaseInput
    {
        private KeyboardState _prevKeyboardState;



        public KeyboardInputs()
        {
            _prevKeyboardState = Keyboard.GetState();
        }

        public override void Update(GameTime gameTime)
        {
            _prevKeyboardState = Keyboard.GetState();
        }

        public override Dictionary<object, ButtonState> GetStates()
        {
            Dictionary<object, ButtonState> returnStates = new Dictionary<object, ButtonState>();

            foreach (Keys key in Enum.GetValues(typeof(Keys)))
            {
                returnStates[key] = ButtonState.Released;
            }

            KeyboardState currentState = Keyboard.GetState();

            foreach (var pressedkey in currentState.GetPressedKeys().ToList())
            {
                returnStates[pressedkey] = ButtonState.Pressed;
            }

            return returnStates;
        }

        public override List<object> JustPressedButtons()
        {
            List<object> returnKeys = new List<object>();

            KeyboardState currentState = Keyboard.GetState();

            foreach (Keys key in Enum.GetValues(typeof(Keys)))
            {
                //if the key is down now and was not down before
                if (currentState.IsKeyDown(key) && _prevKeyboardState.IsKeyUp(key))
                {
                    returnKeys.Add(key);
                }
            }

            return returnKeys;
        }
        
    }
}
